<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计算器</title>
	</head>
	<body>
		<input type="text" name="" id="number1" value="" />
		<select id="symbol">
			<option value="">请选择运算符号</option>
			<option value="">+</option>
			<option value="">-</option>
			<option value="">*</option>
			<option value="">/</option>
		</select>
		<input type="text" name="" id="number2" value="" />
		=
		<input type="text" name="" id="result" value="" />
		<button type="button" onclick="Count();">计算</button>
		<br/><button type="button" onclick="Mainpage();">跳转回主页面</button>
	</body>
	<script type="text/javascript">
		function Count(){
			var number1 = document.getElementById('number1').value;
			var number2 = document.getElementById('number2').value;
			var symbol = document.getElementById('symbol').value;
			if(number1 == ''){
				alert('数值一不能为空!')
			}else if(number2 == ''){
				alert('数值二不能为空!')
			}else{
				number1 = Number(number1)
				number2 = Number(number2)
			
			var result;
			switch(symbol){
				case "+":
				     result = number1 + number2;
				     break;
				case "-":
				      result = number1 - number2;
					  break;
				case "*":
				      result = number1 * number2;
					  break;
				case "/":	  
				      result = number1 / number2;
					  break;
			    default:
				      alert('请选择运算符号')
					  break;
					  }
			    var resultobj = document.getElementById('result');
					resultobj.value = result;
			     }
		}

		function Mainpage(){
			location.href = '主页面.html';
		}
	</script>
</html>
